<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加网站</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/style/admin.css" media="all">
    <script src="${global_templets_skin}/common/js/jquery.min.js"></script>
    <script src="${global_templets_skin}/systemstyle/layui/ztree/jquery.ztree.core-3.5.min.js"></script>
    <script charset="utf-8" src="${global_templets_skin}/kindeditor/kindeditor-all-min.js"></script>
    <script charset="utf-8" src="${global_templets_skin}/kindeditor/lang/zh-CN.js"></script>
    <style>
        .layui-upload-img {
            width: 92px;
            height: 92px;
            margin: 0 10px 10px 0;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">文章发布</div>
                <div class="layui-card-body" pad15>

                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">文章标题</label>
                            <div class="layui-input-block">
                                <input type="text" name="title" value="" lay-verify="required" placeholder="请填写文章标题" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">简短标题</label>
                            <div class="layui-input-block">
                                <input type="text" name="shorttitle" value="" placeholder="请填写文章简短标题" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">上级分类</label>
                            <div id="columnform"></div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">封面图</label>
                            <div class="layui-input-block">
                                <div class="layui-card-body">
                                    <div class="layui-upload">
                                        <input type="hidden" name="titlepic" id="titlepic" value="">
                                        <button type="button" class="layui-btn" id="upload-normal">上传图片</button>
                                        <div class="layui-upload-list">
                                            <img class="layui-upload-img" id="upload-normal-img">
                                            <p id="upload-demoText"></p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">文章来源</label>
                                    <div class="layui-input-inline">
                                        <input type="tel" name="source" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">文章作者</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="writer" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">文章描述</label>
                                <div class="layui-input-block">
                                    <textarea name="description" class="layui-textarea"
                                              placeholder="出现核心的关键词，必须完整的出现在描述中。描述长度155个字符。"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">文章内容</label>
                                <div class="layui-input-block">
                                    <textarea name="content" id="content" class="layui-textarea"
                                              style="height:500px;"></textarea>
                                    <script>
                                        //装载编辑器
                                        KindEditor.ready(function (K) {
                                            K.create('#content',
                                                {
                                                    uploadJson: '/member/kindEditorUpload',
                                                    //fileManagerJson : '../asp/file_manager_json.asp',
                                                    //allowFileManager : true,
                                                    allowImageRemote: false,
                                                    "filterMode": false,
                                                    afterBlur: function () {
                                                        this.sync();
                                                    }
                                                });
                                        });
                                    </script>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <input type="hidden" name="siteId" id="siteId" value="${siteId!}">
                                    <button class="layui-btn" lay-submit lay-filter="addNews">确认保存</button>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="${global_templets_skin}/systemstyle/layui/layui.js"></script>
    <script>
        layui.config({
            base: '${global_templets_skin}/systemstyle/' //静态资源所在路径
        }).extend({
            selectN: '../layui/layui_extends/selectN',
            index: 'lib/index' //主入口模块
        }).use(['index', 'upload', 'set', 'selectN'], function () {
            var form = layui.form
                , $ = layui.jquery
                , layer = layui.layer
                , selectN = layui.selectN
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#upload-normal'
                , url: '/member/layuiUpload'
                , accept: 'images' //只允许上传图片
                , multiple:false   //支持多文件上传
                , acceptMime: 'image/*'
                , size: 1024*2 //限定大小
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#upload-normal-img').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg(res.msg);
                    }
                    $("#titlepic").val(res.data.src);
                    //上传成功
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#test-upload-demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });

            //无限级分类-所有配置
            var catIns2 = selectN({
                //元素容器【必填】
                elem: '#columnform'
                //候选数据【必填】
                , data: "/member/column/columnselect.do?siteid=${siteId!}&channel=${column.channel!}"
                //设置了长度
                , width: null
                //默认值
                ,selected: ${fatherNode!} //["369289385704685568", "381767141860311040"]
                //为真只取最后一个值
                , last: true
                //空值项提示，可设置为数组['请选择省','请选择市','请选择县']
                , tips: '请选择'
                //事件过滤器，lay-filter名 不设置与选择器相同(去#.)
                , filter: ''
                //input的name 不设置与选择器相同(去#.)
                , name: 'columnId'
                //数据分隔符
                , delimiter: ','
                //数据的键名
                , field: {idName: 'id', titleName: 'name', statusName: 'status', childName: 'children'}
                //表单区分 form.render(type, filter); 为class="layui-form" 所在元素的 lay-filter="" 的值
                , formFilter: null
                , verify: 'required'
            });

            form.on('submit(addNews)', function (data) {
                $.ajax({
                    url: '/member/news/add.do',
                    type: 'post',
                    dataType: 'json',
                    data: data.field,
                    success: function (e) {
                        if (e.code == "0") {
                            layer.msg('成功');
                            window.location.reload();
                        } else {
                            layer.msg(e.message);
                        }
                    }
                })
                //防止页面跳转
                return false;
            });

        });
    </script>
</body>
</html>